//
// Created by postgres on 5/11/17.
//
#include "../include/07graph/graph.h"
void  CreateALGraph(GraphAdjList *G)
{
    G->numVertexes = 4;
    //G->numEdges = 4;
    char vertexes[] = "a,b,c,d";
    char edges[] = "0,1;0,2;0,3;1,0;1,2;2,0;2,1;2,3;3,0;3,2";
    int i=0, j=0,n=0, k, w;
    char delimiters1[] = ";";
    char delimiters2[] = ",";
    /* 读入顶点信息,建立顶点表 */
    char *wrk, *rv1, *rv2;
    wrk = vertexes;
    while ((rv1 = str_split(&wrk, delimiters1))) {
        G->adjlist[n].data = *rv1;
        G->adjlist[n].firstedge=NULL;
        n++;
    }
    wrk = edges;
    while((rv1 = str_split(&wrk, delimiters1))){
        rv2 = str_split(&rv1, delimiters2);
        i = atoi(rv2);
        rv2 = str_split(&rv1, delimiters2);
        j = atoi(rv2);
        EdgeNode *p;
        if(!(G->adjlist[i].firstedge)){
            p=palloc(sizeof(EdgeNode));
            p->adjvex=j;
            p->next=NULL;
            G->adjlist[i].firstedge=p;
        }
        else{
            p=G->adjlist[i].firstedge;
            while(p->next)
                p=p->next;
            p->next=palloc(sizeof(EdgeNode));
            p->next->adjvex=j;
            p->next->next=NULL;
        }
    }

}


void AdjListGraph_test() {
    GraphAdjList adjList;
    CreateALGraph(&adjList);

}